 
/*首页获取登录信息并且渲染首页顶部*/
function headHtml(){
	var uid = $("#useridoflogin").val();
	var usertype = $("#usertypeoflogin").val();
	var token = $("#token").val();
	var headHtml = "";
	if(usertype == '3'){
		headHtml += '<li id="btnLink" onclick="btnLinkclick()" ><a >'+token+'<span><img\
							src="images/sy_down.png"> </span></a></li>\
					<li><a href="new_file20">海洋装备</a></li>\
					</ul>\
					<ul id="thediv" style="display: none;">\
					<li><a href="new_file46">用户中心</a></li>\
					<li><a onclick="out()" href=outlogin>退出登录</a></li>';
		$(".headHtml").html(headHtml);
	}else{
		if(uid != 'null' && uid != ''){
			userInfo(uid,usertype,token);
		}else{
			headHtml += '<li><a href="http://xmsoc.com:20507/OCEAN/register/goRegister">注册</a> </li><li><a href="http://xmsoc.com:20507/OCEAN/toLogin?url='+indexUrl+'">登录</a> </li><li><a href="new_file20">海洋装备</a></li><li><a href="zj_login.jsp">专家登录</a></li>';
			$(".headHtml").html(headHtml);
		}
	}
}

/*清除sessionStorage中的数据*/
function out(){
	if(sessionStorage!=null){
		sessionStorage.clear();
	}
}

/*获取登录用户的信息*/
function getUser(uid,usertype,token){
	$.ajax({
		url:Server +"/thirdparty/user/getUserInfoById",
		type:"POST",
		data:{
			"uid":uid,
			"token":token,
			"type":usertype
		},
		dataType:"json",
		success:function(data){
			var headHtml = "";
			var userUrl = "";
			var userInfo = data["userInfo"];
			if(userInfo != "" && userInfo != null){
				if(usertype == 1){
					userUrl = "new_file39";
				} else if(usertype == 2){
					userUrl = "new_file40";
				} else if(usertype == 3){
					userUrl = "new_file46";
				}
				headHtml += '<li id="btnLink" onclick="btnLinkclick()" ><a >'+userInfo['account']+'<span><img\
					src="images/sy_down.png"> </span></a></li>\
		<li><a href="new_file20">海洋装备</a></li>\
	</ul>\
	<ul id="thediv" style="display: none;">\
		<li><a href='+userUrl+'>用户中心</a></li>\
		<li><a onclick="out()" href=outlogin>退出登录</a></li>';
				$(".headHtml").html(headHtml);
			}
		},
		error:function(data){
			console.log("失败");
		}
	});
}


function btnLinkclick(){
	if($("#thediv").css("display")=="none"){
		$("#thediv").show();
	}else{
		$("#thediv").hide();
	}

}





/*获取登录状态*/
function userInfo(uid,usertype,token){
	$.ajax({
		url:Server + '/thirdparty/user/userInfo',
		type:'POST',
		data:{
			'uid':uid,
			'type':usertype,
			'token':token
		},
		dataType : "json",
		success:function(data){
			if(data.code == 0 && data.userInfo != null){
				console.log("登录状态有效");
				getUser(uid,usertype,token);
			}else{
				alert("登录状态已失效,请重新登录");
				$(location).attr("href","http://xmsoc.com:20507/OCEAN/toLogin?url="+Server+"/")
			}
			
		},
		error:function(data){}
	});
}



// $(document).ready(function(e) {
//     $("#link").click(function(e) {
//         $("#thediv").toggle();
//     });
// });

	
	// $("#link").click(function(){
	// 		if($("#thediv").css("display")=="none"){
	// 			$("#thediv").show();
	// 		}else{
	// 			$("#thediv").hide();
	// 		}
	// 	});


